package com.example.PullToRefreshDemo;

import android.content.Context;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import com.xqkad.android.ui.PullToRefreshLayout;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        init_lv(this);
        final PullToRefreshLayout mygp = (PullToRefreshLayout) findViewById(R.id.refresh_layout);
        mygp.setOnRefreshListener(new PullToRefreshLayout.OnRefresh() {
            @Override
            public void onStartRefresh() {
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        try {
                            Thread.sleep(3000);
                            mygp.reset();
                        } catch (InterruptedException e) {

                        }
                    }
                }).start();
            }
        });
    }

    void init_lv(Context context){
        ListView lv = (ListView) findViewById(R.id.lv1);

        final String[] datas = new String[] { "张三", "李四", "王五", "麻子", "习大", "壁虎", "凯撒", "老罗",
                "张三2", "李四2", "王五2", "麻子2", "习大2", "壁虎2", "凯撒2", "老罗2",
                "域名", "韩寒", "柴静", "马云", "老马", "李彦宏", "老周", "朝阳兄" };
        final ArrayAdapter<String> adapter = new ArrayAdapter<String>(context,
                android.R.layout.simple_expandable_list_item_1, datas);
        if(lv != null)
            lv.setAdapter(adapter);
    }
}
